package com.zoshine.zzg.pojo.pojostatus;

import com.zoshine.zzg.base.Status;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品状态枚举
 *
 * @author 贾俊峰
 * @time 2017/6/20 17:42
 */
public enum FamilyMemberOrderStatus {
    INIT(10, "待支付"),
    AUDIT_SEND(20, "待发货"),
    AUDIT_RECEIVE(30, "待收货"),
	PUBLISH(90, "订单完成"),
    REVOKE(99, "订单撤销");

    private int value;
    private String desc;
    FamilyMemberOrderStatus(final int value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public static String getDesc(Integer value) {
        for (FamilyMemberOrderStatus goodsStatus : FamilyMemberOrderStatus.values()) {
            if (Objects.equals(goodsStatus.value, value)) {
                return goodsStatus.desc;
            }
        }
        return null;
    }

    // 缓存一个列表，防止每次使用都进行循环
    private static List<Status> statusList;
    public static List<Status> getList() {
        if (statusList == null || statusList.size() == 0) {
            statusList = new ArrayList<>();
            for (FamilyMemberOrderStatus commonStatus : FamilyMemberOrderStatus.values()) {
                // 将状态存入列表
                Status status = new Status();
                status.setValue(commonStatus.value);
                status.setDesc(commonStatus.desc);
                statusList.add(status);
            }
        }
        return statusList;
    }
}
